package com.google.gson.internal.bind;

import com.google.gson.a.a;
import com.google.gson.internal.bind.TypeAdapter.Factory;
import com.google.gson.internal.f;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class l {
    private final ThreadLocal a;
    private final List b;

    private l(m mVar) {
        this.a = new ThreadLocal(this) {
            final /* synthetic */ l a;

            {
                this.a = r1;
            }

            protected Map a() {
                return new HashMap();
            }

            protected /* synthetic */ Object initialValue() {
                return a();
            }
        };
        f fVar = new f();
        List arrayList = new ArrayList();
        if (mVar.a) {
            arrayList.add(y.e);
            arrayList.add(y.k);
            arrayList.add(y.q);
            arrayList.add(y.o);
            arrayList.add(y.m);
            arrayList.add(y.w);
        }
        arrayList.addAll(mVar.b);
        if (mVar.a) {
            arrayList.add(new d(fVar));
            arrayList.add(new u(fVar));
            arrayList.add(a.a);
            arrayList.add(o.a);
            arrayList.add(new q(fVar));
        }
        this.b = Collections.unmodifiableList(arrayList);
    }

    public TypeAdapter a(a aVar) {
        Map map = (Map) this.a.get();
        TypeAdapter typeAdapter = (n) map.get(aVar);
        if (typeAdapter == null) {
            n nVar = new n();
            map.put(aVar, nVar);
            try {
                for (Factory create : this.b) {
                    typeAdapter = create.create(this, aVar);
                    if (typeAdapter != null) {
                        nVar.a(typeAdapter);
                    }
                }
                throw new IllegalArgumentException("This MiniGSON cannot handle " + aVar);
            } finally {
                map.remove(aVar);
            }
        }
        return typeAdapter;
    }

    public TypeAdapter a(Factory factory, a aVar) {
        Object obj = null;
        for (Factory factory2 : this.b) {
            if (obj != null) {
                TypeAdapter create = factory2.create(this, aVar);
                if (create != null) {
                    return create;
                }
            } else if (factory2 == factory) {
                obj = 1;
            }
        }
        throw new IllegalArgumentException("This MiniGSON cannot serialize " + aVar);
    }

    public TypeAdapter a(Class cls) {
        return a(a.b(cls));
    }
}
